import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { ServiceNode } from '../entities/service-node.entity';
import { ServiceEdge } from '../entities/service-edge.entity';

@Injectable()
export class TopologyService {
  constructor(
    @InjectRepository(ServiceNode)
    private nodeRepo: Repository<ServiceNode>,
    
    @InjectRepository(ServiceEdge)
    private edgeRepo: Repository<ServiceEdge>,
  ) {}
  
  async getTopology(): Promise<{ nodes: ServiceNode[]; edges: ServiceEdge[] }> {
    return {
      nodes: await this.nodeRepo.find(),
      edges: await this.edgeRepo.find({ relations: ['source', 'target'] }),
    };
  }
}